/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.filemanager;

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 *
 * @author Wahyu Fahmy
 */
public class WriteFile {
    private String filename = "";
    FileWriter fstream;
    BufferedWriter out;

    public WriteFile(String name){
        // Create file
        try {
            fstream = new FileWriter(name);
            this.filename = name;
            out = new BufferedWriter(fstream);
        } catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }

    public void write(String line){
        try {
            out.write(line + "\n");
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }

    public void close(){
        try {
            out.close();
        } catch (Exception e){
            System.err.println("Error: " + e.getMessage());
        }
    }

    public static void main(String[] arg){
        WriteFile wf = new WriteFile("dir_bujang/results/testtulis.txt");
        wf.write("ada isinya");
        wf.write("isinya apa");
        wf.write(" apa aja daaah");
        wf.close();
    }
}
